// export class Chain {
//   static NEXT_SUCCESSOR = 'nextSuccessor';
//   successor = noop;
//   fn = noop;
//
//   constructor(fn, successor) {
//     this.fn = fn
//     this.successor = successor
//   }
//
//   setNextSuccessor(successor) {
//     return this.successor = successor
//   }
//
//   //  do chain method
//   passRequest(...args) {
//     const ret = this.fn.apply(this, args) //  this 不会指向 vue 组件实例
//     if (ret === Chain.NEXT_SUCCESSOR) {
//       return this.successor && this.successor.passRequest.apply(this.successor, args)
//     }
//     return ret
//   }
// }

const noop = function() {

}

const Chain = {
  // NEXT_SUCCESSOR: 'nextSuccessor',
  successor: noop,
  fn: noop,

  of() {
    return Object.create(Chain)
  },
  setNextSuccessor(successor) {
    return this.successor = successor
  },

  // passRequest(...args) {
  //   if (this.fn(args) !== Chain.NEXT_SUCCESSOR) {
  //     return
  //   }
  //   this.invoke(args)
  // },

  next(...args){
    this.fn(args)
    this.invoke(args)
  },

  invoke(args){
    if (!this.successor) {
      return
    }
    if (Object.prototype.toString.call(this.successor.fn) === '[object Function]') {
      this.successor.next(args)
    } else {
      console.warn('the fn in successor must be a function ! ')
    }
  }
}

// Object.defineProperty(Chain, 'NEXT_SUCCESSOR', {
//   writable: false,
//   configurable: false
// })

export { Chain }





